package com.woniuxy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.entity.Procurement;
import com.woniuxy.service.ProcurementService;
import com.woniuxy.utils.Result;

@Controller
@RequestMapping("/procurement")
public class ProcurementController {
	@Autowired
	private ProcurementService procurementService;
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/findProcurement")
	@ResponseBody
	public List<Procurement> findProcurement(){
		return procurementService.findProcurement();
		
	}
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/findProcurementByOrderno")
	@ResponseBody
	public Procurement findProcurementByOrderno(String orderno){
		return procurementService.findProcurementByOrderno(orderno);
		
	}
	
	@RequiresPermissions("manager:add")
	@RequestMapping("/insertProcurement")
	@ResponseBody
	public Result<String> insertProcurement(Procurement procurement){
		Result<String> result=new Result<>();
		int i=procurementService.insertProcurement(procurement);
		if (i!=0) {
			result.setMessage("插入成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:update")
	@RequestMapping("/updateProcurement")
	@ResponseBody
	public Result<String> updateProcurement(Procurement procurement){
		Result<String> result=new Result<>();
		int i= procurementService.updateProcurementByOrderno(procurement);
		if (i!=0) {
			result.setMessage("修改成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:del")
	@RequestMapping("/delProcurement")
	@ResponseBody
	public Result<String> updateProcurement(String orderno){
		Result<String> result=new Result<>();
		int i= procurementService.delProcurementByOrderno(orderno);
		if (i!=0) {
			result.setMessage("删除成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:update")
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Result<String> changeStatus(Procurement procurement){
		Result<String> result=new Result<>();
		int i=procurementService.changeStatus(procurement);
		int ii=procurementService.changeStatusbyno(procurement);
		int iii=procurementService.changeStatusbyor(procurement);
		if (i!=0 && ii!=0 && iii!=0) {
			result.setMessage("采购完成");
		}
		return result;
	}
}
